package API.DateDome.LocalDateTimeDome;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * ClassName:LocalDateTimeText008
 * Package:API.DateDome.LocalDateTimeDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/2-19:56
 * @Version:v1.0
 */
public class ChronoUnitDome {
    public static void main(String[] args) {
        LocalDateTime nowlocalDateTime = LocalDateTime.now();
        System.out.println(nowlocalDateTime);
        //出生日期的时间对象
        LocalDateTime birthDate = LocalDateTime.of(2000, 4, 4,
                4, 4, 4, 5452);
        System.out.println(birthDate);


        System.out.println("相差的年数：" + ChronoUnit.YEARS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的月数：" + ChronoUnit.MONTHS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的周数：" + ChronoUnit.WEEKS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的天数：" + ChronoUnit.DAYS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的时数：" + ChronoUnit.HOURS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的分数：" + ChronoUnit.MINUTES.between(birthDate, nowlocalDateTime));
        System.out.println("相差的秒数：" + ChronoUnit.SECONDS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的毫秒数：" + ChronoUnit.MILLIS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的纳秒数：" + ChronoUnit.NANOS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的半天数：" + ChronoUnit.HALF_DAYS.between(birthDate, nowlocalDateTime));
        System.out.println("相差的十年数：" + ChronoUnit.DECADES.between(birthDate, nowlocalDateTime));
        System.out.println("相差的世纪(百年)数：" + ChronoUnit.CENTURIES.between(birthDate, nowlocalDateTime));
        System.out.println("相差的千年数：" + ChronoUnit.MILLENNIA.between(birthDate, nowlocalDateTime));
        System.out.println("相差的纪元数：" + ChronoUnit.ERAS.between(birthDate, nowlocalDateTime));

    }
}
